#!/usr/bin/env python
################################################################################
#
#   General utility
#
#
#   Copyright (C) 2007 Leo Goodstadt
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; version 2
#   of the License
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#################################################################################

import sys
from wrap_text import wrap_text

def warn_error(Msg, logger=None):
    """
    Standard way of dying after a fatal error
    """
    print_error (Msg, logger)
    sys.exit()

def die_error(Msg, logger=None):
    """
    Standard way of dying after a fatal error
    """
    print_error (Msg, logger)
    sys.exit()

def print_error (Msg, logger=None):
    """
    Standard way of printing error
    """
    sys.stderr.write("\nError:\n" + wrap_text(Msg, "\t", "") + "\n")
    if logger:
        logger.error(Msg)

def print_warning (Msg, logger=None):
    """
    Standard way of printing error
    """
    sys.stderr.write("\nWarning:\n" + wrap_text(Msg, "\t", "") + "\n")
    if logger:
        logger.warning(Msg)

def unit_test():
    import doctest
    doctest.testmod()

    
    
        
import os
from os.path import split, abspath,exists
def prepare_directory_for_file (file_name):
    file_path = split(abspath(file_name))[0]
    if not exists(file_path):
        os.makedirs(file_path)
    
    
if __name__ == '__main__':
    unit_test()




